:: AutoMySQLBackupForWindows Servers By Matt Moeller  v.1.2
:: RED OLIVE DESIGN INC.

:: Follow us on twitter for updates to this script  twitter.com/redolivedesign
:: coming soon:  email admin a synopsis of the backup with total file size(s) and time it took to execute

:: UPDATED 12.29.2011  

:: Thanks to Kamil Tomas for catching and resolving the time bug
:: If the time is less than two digits insert a zero so there is no space to break the filename

set year=%DATE:~10,4%
set day=%DATE:~7,2%
set mnt=%DATE:~4,2%
set hr=%TIME:~0,2%
set min=%TIME:~3,2%

IF %day% LSS 10 SET day=0%day:~1,1%
IF %mnt% LSS 10 SET mnt=0%mnt:~1,1%
IF %hr% LSS 10 SET hr=0%hr:~1,1%
IF %min% LSS 10 SET min=0%min:~1,1%

set backupdate=%year%-%day%-%mnt%-%hr%-%min%

 

:: MySQl DB user
set dbuser=admin

:: MySQl DB users password
set dbpass=Awale##aaxc973

:: Switch to the MySQL data directory and collect the folder names
pushd "C:\Program Files (x86)\Parallels\Plesk\Databases\MySQL\data"

:: Loop through the folders and use the fnames for the sql filenames, collects all databases automatically this way

echo "hello"

echo "Pass each name to mysqldump.exe and output an individual .sql file for each"

FOR /D %%F IN (crown) DO (
"C:\Program Files (x86)\Parallels\Plesk\Databases\MySQL51\bin\mysqldump.exe" --user=%dbuser% --password=%dbpass% --databases %%F > "c:\apps\MySQLBackups\backupfiles\%%F.%backupdate%.sql"
)

echo "Zipping all files ending in .sql in the folder"

"c:\apps\MySQLBackups\zip\7za.exe" a -tzip "c:\apps\MySQLBackups\backupfiles\FullBackup.%backupdate%.zip" "c:\apps\MySQLBackups\backupfiles\*.sql"

echo "Deleting all the files ending in .sql only"

del "c:\apps\MySQLBackups\backupfiles\*.sql"

echo "Deleting zip files older than 10 days now"
Forfiles -p c:\apps\MySQLBackups\backupfiles\ -s -m *.* -d -10 -c "cmd /c del /q @path"
echo "All done, pretty slick eh"

 

::FOR THOSE WHO WISH TO FTP YOUR FILE UNCOMMENT THESE LINES AND UPDATE - Thanks Kamil for this addition!

cd\ 
cd c:\apps\MySQLBackups\backupfiles
@echo off
echo user shuuke>ftpup.dat
echo Awale##aaxc973>>ftpup.dat

::echo [optional line; you can put "cd" command to navigate through the folders on the ftp server; eg. cd\folder1\folder2]>>ftpup.dat
echo binary>>ftpup.dat
echo put FullBackup.%backupdate%.zip>>ftpup.dat
echo quit>>ftpup.dat
ftp -n -s:ftpup.dat 208.109.96.16
del ftpup.dat
cd..